home *** CD-ROM | disk | FTP | other *** search
- <?xml version="1.0" encoding="utf-8"?>
- <!-- ===========================================================
- Category: XSLT
- Sub-category: xsl:element
- Author: David Silverlight
- HeadGeek@xmlpitstop.com
- Created: 2001-05-16
- Description:-
- This stylesheet processes a set of XML elements as input and
- creates a new set of xml elements as output. In this
- example we are using the several xslt functions along with
- xsl:element to create two new xml elements(firstname and
- lastname) from our input as well as creating a third
- element directly from the xml input (department).
- ================================================================ -->
- <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
- <xsl:output method="xml"/>
-
-
-
- <!-- Template for root rule -->
- <xsl:template match="/">
- <xsl:apply-templates/>
- </xsl:template>
-
-
- <!-- Template for "employees" elements -->
- <xsl:template match="employees">
- <!--This stylesheet processes a set of XML elements and
- uses the xsl:element element to generate a new xml file containing elements
- in their original form as well as newly generated elements such as firstname
- and lastname.-->
-
- <!-- Generate the "employees element" -->
- <xsl:element name="bademployees" >
-
-
- <xsl:for-each select="employee" >
-
- <xsl:sort select="department" order="ascending" />
- <xsl:element name="employee" >
-
- <xsl:element name="department">
- <xsl:value-of select="department"/>
- </xsl:element>
-
-
- <!-- Here we are creating an element that is a variation from
- the original source document. In this example we are breaking
- up employee name into two seperate elements (firstname and lastname) -->
- <xsl:element name="firstname">
- <xsl:value-of select="substring-before(employeename, ' ')" />
- </xsl:element>
-
-
- <!-- We can also create variables set with contents that we create and use the
- variables in our elements. Note: We are doing the same as with firstname
- but just accomplishing it with the use of an xsl:varialbe. -->
- <xsl:element name="lastname">
- <xsl:variable name="lastname" select="substring-after(employeename, ' ')" />
- <xsl:value-of select="$lastname" />
- </xsl:element>
-
- </xsl:element>
- </xsl:for-each>
- </xsl:element>
- </xsl:template>
-
-
-
- </xsl:stylesheet>